import json
import time
import bcrypt
import pytest
import requests


def get_key():
    # 测试环境获取key
    password = b"Creek)Ew&IzihGz9@pyb)qm"
    # 正式环境
    # password = b"Creek)EkmkAwRko3u8&PY!"
    hashed = bcrypt.hashpw(password, bcrypt.gensalt())
    return hashed.decode('utf-8')
    # print(TestRequest.access_key)


# print(get_key())
class TestRequest:
    # 全局变量
    sess = requests.session()
    access_token = ""
#
#
# #测试环境用户登录并获取token存入全局变量中
#     @classmethod
#     def get_token(classs):
#         data = {
#             # "email": "123456123@163.com",
#             "email": "123457890a@163.com",
#             "key": get_key(),
#             "password": "TtToBhIcpiuSRrhtP58H3wj2WZxp9TMpBNLkBSYw8fCNWTqBby/HtiKCgucRKta8Mc16SL+FuUHn7G40rx7OAwItM/CF6L0veZBJYBKF7o8XZxuuV//6LaJ21CQfNO5jIZJbWs9Lj2i/llfc56AfYfYB46ktaHUvuf7ggKs8haGv+FeUP+NyyrNTFw4Cw/pve1fA14h9DtOat0X7o52jVW6tqCpHu0EpO2wgoXLE8lmJSKiflzsPcsIHKOX5LBAxEq+sziq+gFrcqAIpGzL1U33dGHorLzIiTUzJ5Fi5wn7KVdOY4kzzWqE1pCxgkhoAcdyOK7PSHTxrXR7hVI+dug==",
#             "customerCode": "XCKJ",
#             "mobileId": "c9febf06aa66e467"
#         }
#         resp = classs.sess.request("post", r"http://test-center.creekwearable.com:9501/service-user/v1/auth/login",json=data)
#         token =resp.json()["data"]["token"]
#         TestRequest.access_token = token
#         # headers = {"Authorization": f"{TestRequest.access_token}"}
#         # print(headers)
#
#
#
#
# def get_refreshtoken():
#     data = {
#         "refreshToken": TestRequest.access_token
#     }
#     resp = TestRequest.sess.request(method="post",url=r"http://test-center.creekwearable.com:9501/service-user/v1/auth/token/refresh",json=data)
#     retoken = resp.json()["data"]["refreshToken"]
#     return  retoken
#
# 游客登录
def get_token():
    data = {
        "countryCode": "CN",
        "customerCode": "XCKJ",
        "key": get_key(),
        "mobileId": "37f971b4755ee7302a4b644742860281c35a7e62527c36bc29deefb8d24463eb"
    }
    resp = TestRequest.sess.request(method="post",url=r"http://test-center.creekwearable.com:9501/service-user/v1/auth/token",json=data)
    # mobil = resp.json()["data"]["mobileIdChange"]
    assert resp.json()["data"]["mobileIdChange"] != None



print(get_token())





# #表盘市场接口并判断返回值是否正确
# def est_classfy():
#     url = r"http://test-center.creekwearable.com:9501/service-parts/v1/dial/classify/list"
#     headers = {"Authorization": f"{TestRequest.access_token}"}
#     data = {
#         "firmwareId":1018,
#         "appFrameVersion":6,
#         "firmwareFrameVersion":9,
#         "customerCode":"AIXW",
#         "langId": 0
#     }
#     resp = TestRequest.sess.request(method="post",url= url,headers = headers,json=data)
#     print(resp.json()["data"]["sort"])




# time.sleep(1)

# est_classfy()


#账号注销接口
# def logoff():
#     url = r"http://test-center.creekwearable.com:9501/service-user/v1/auth/logoff"
#     headers = {"Authorization": f"{TestRequest.access_token}"}
#     data = {
#         "password":"eAnKsf4eeSAmNfqJCVtfIS19+77vmIcErflPSDnT0H7JIGXBjsAWlEXK1NvvpUPO+1fwTJGxu0El4BbjYneyuID5lA0W4""HEqcOOBFLPHz3wZiehnncVLtaZjLvKn/fjQTjWRHeWSus4c5APQRPluzDhrYoMaWSMag2h0Yzk2GL9JxARCwOvAO7dlHMFlizdsHKNfOFsL1Biw7zRf+LRo4TyiuSroT2r/C9IedmQVUkgjjzcoEAR347vs4ADSTqVjnh3NsPr3jPZsk+YILHENzfx0X2nRT/Rg1lTg2if9SEzB0/TSihKRwFf+ddFbcsfMUPWa2SWFOgo/CYLQIj3mmg=="
#     }
#     resp = TestRequest.sess.request(method="post", url=url,headers=headers, json=data)
#     print(resp)
#
#
# TestRequest.get_token()
# print(logoff())
#发送邮箱
# def send_email():
#     url = r"http://test-center.creekwearable.com:9501/service-user/v1/email/send"
#     data ={
#         "email":"3301068094@qq.com",
#         "type":"4",
#         "appName":"Fitbeing",
#         "key":get_key()
#     }
#     resp = requests.request(method="post", url=url, json=data)
#     print(resp)
#
#
# send_email()